package com.hnkywl.sts.service.htgl;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.htgl.ZjbchtDao;
import com.hnkywl.sts.entity.htgl.Xsht;
import com.hnkywl.sts.entity.zjgl.Bzjyj;
import com.hnkywl.sts.util.BaseUtils;
import net.ruixin.orm.hibernate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by HL on 2016/4/18.
 */
@Service
public class ZjbchtService {
    private ZjbchtDao  zjbchtDao;

    public String findZjbcHtList(String zt, String xslx, String htbh, Long ssgsId, Long ssbmId, Long xsrId, Long hzfId, Date startDate, Date endDate, String htbm, int pageNo, int pageSize) {
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        Page<Xsht> xshtPage = this.zjbchtDao.findZjbcHtList(zt, xslx, htbh, ssgsId, ssbmId, xsrId, hzfId, startDate, endDate, htbm, pageNo, pageSize);
        String xshtJson = gson.toJson(xshtPage.getResult());
        return "{\"total\":" + xshtPage.getTotalCount() + ",\"rows\":" + xshtJson + "}";
    }




    public String findZjbchtList1(String htbm,Integer pageNo, Integer pageSize){
        Page<Map> page = zjbchtDao.findbzjyjList1(htbm,pageNo, pageSize);

        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        String json = gson.toJson(page.getResult());
        return "{\"total\":" + page.getTotalCount() + ",\"rows\":" + json + "}";
        /*Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        String json = gson.toJson(list);*/
        // return "{\"rows\":" + json + "}";
    }

    public String findZjbchtmxDetail1(Long xshtId, int pageNo, int pageSize) {
        if (xshtId != null) {
            Gson gson = new Gson();
            Page<Map> page = this.zjbchtDao.findZjbchtmxList1(xshtId, pageNo, pageSize);
            List<Map> xshtmxList = page.getResult();
            Map sum = zjbchtDao.findZjbchtHj(xshtId);
            String json = gson.toJson(xshtmxList);
            return "{\"total\":" + page.getTotalCount() + ",\"rows\":" + json + ",\"footer\":[{\"cd.z\":\"合计:\",\"sbsl\":" + sum.get("sbsl") + ",\"hsje\":" + sum.get("hsje") + "}]}";
        } else
            return "{\"total\":0,\"rows\":[],\"footer\":[{\"cd.z\":\"合计:\",\"sbsl\":0,\"hsje\":0}]}";
    }


    public String findZjbchtmxDetail(Long xshtId) {
        Gson gson = new Gson();
        String result = "";

        List<Map> xsdbzjList = this.zjbchtDao.findZjbchtmxList(xshtId);

        result = "{\"rows\":" + gson.toJson(xsdbzjList) + "}";

        return result;
    }


    public Xsht findZjbchtDetail(Long xshtId) {
        return this.zjbchtDao.get(xshtId);
    }


    public void findhtce(Long xsdId){
        String htce = zjbchtDao.findhtce(xsdId);

       // return htce;

    }

    @Autowired
    public void setZjbchtDao(ZjbchtDao zjbchtDao) {
        this.zjbchtDao = zjbchtDao;
    }
}
